package common.server.utils;

import javax.servlet.http.HttpServletResponse;

/**
 * @author by Lianghuan
 * @create 2018-01-04 18:33
 **/

public class ResponseHeaderUtil {
    /**
     * ACCESS_ORIGIN_ALL 内网接收所有跨域来源
     */
    public static final String ACCESS_ORIGIN_ALL = "*.hl139.net";

    /**
     * ALLOW_HEADERS 复杂跨域请求允许header中设置其他属性
     */
    public static final String ALLOW_HEADERS = "Origin, X-Requested-With, Content-Type, Accept";
    /**
     * MAX_AGE 客户端在此时间内不重复发送跨域探测请求
     */
    public static final String MAX_AGE = "3600";

    /**
     * <设置H5跨域Cors头部属性>
     * <功能详细描述>
     * @param response
     * @see [类、类#方法、类#成员]
     */
    public static void setH5CorsHeader(HttpServletResponse response) {
        response.addHeader("Access-Control-Allow-Origin", ACCESS_ORIGIN_ALL);
        response.addHeader("Access-Control-Allow-Headers", ALLOW_HEADERS);
        response.addHeader("Access-Control-Max-Age", MAX_AGE);
        response.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
    }
}
